const app = getApp()
const util = require('../../../utils/util.js')

// 返回处理
const handleRes = (response, fn, url, data, confirmFn) => {
  console.log(url, 'res-->>', response)
  if (response.statusCode == 200) {
    if (response.data.result == 100000) {
      wx.reLaunch({
        url: '../index/index',
      })
      return
    } else if ((response.data.result == 0 || response.data.result === undefined) && typeof fn == 'function') {
      fn(response.data)
      return;
    } else if (response.data.result == 1001) {
      wx.showModal({
        title: '温馨提示',
        confirmColor: '#8290DD',
        content: response.data.description,
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定');
            if (confirmFn) {
              confirmFn(true);
            }
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      })
      return;
    } else {
      wx.showModal({
        title: '温馨提示',
        confirmColor: '#8290DD',
        showCancel: false,
        content: response.data.description
      })
    }
  } else {
    // app.sendLog(url, JSON.stringify(response), JSON.stringify(data));
    wx.showToast({
      title: '服务' + response.statusCode,
      image: '/images/gantan.png',
      duration: 2500
    })
    return;
  }
}

const handleErr = (error, url, data) => {
  console.log(url, 'error-->>', error)
  wx.showToast({
    title: '请求失败请重试',
    image: '/images/gantan.png',
    duration: 2500
  })
}

const handleRequest = (data, fn, url, confirmFn) => {

  handleRequestCallback(data, fn, url, confirmFn)

}

const handleRequestCallback = (data, fn, url, confirmFn) => {
  wx.showLoading({
    title: '加载中...',
    mask: true
  })

  wx.request({
    url: util.CONST_DATA.BASE_URL + url,
    header: header,
    method: method,
    data: data,
    success: function (response) {
      wx.hideLoading()
      handleRes(response, fn, url, data, confirmFn)
    },
    fail: function (error) {
      wx.hideLoading()
      handleErr(error, url, data)
    }
  })
}


const header = app.globalData.header
const method = 'POST'

const lbbTaskService = {
 /**
   * 获取当前师傅或师傅列表
   */
  getWorker: (data, fn) => {
    let url = 'api/task/user'
    handleRequest(data, fn, url)
  },
  /**
   * 获取基本配置信息
   */
  getTaskList: (data, fn) => {
    let url = 'photo/taskList'
    handleRequest(data, fn, url)
  },

  /**
   * 设置任务的时间周期
   * @param {*} data 
   * @param {*} fn 
   */
  setTaskTimeConf:(data, fn) =>{
    let url = 'photo/setTimeConf'
    handleRequest(data, fn, url)
  },

  /**
   * 获取拍照时间配置列表
   * @param {*} data 
   * @param {*} fn 
   */ 
  getTaskTimeConf:(data, fn) =>{
    let url = 'photo/taskTimeConfList';
    handleRequest(data, fn, url)
  },

  /**
   * 根据id获取拍照配置信息
   * @param {*} data 
   * @param {*} fn 
   */
  getTaskTimeConfById:(data, fn)=>{
     let url = 'photo/getTaskTimeConfById'
     handleRequest(data, fn, url)
  },
  
  /**
   * 删除拍照任务时间配置
   * @param {*} data 
   * @param {*} fn 
   */
  delTaskTimeConfById:(data, fn)=>{
    let url = 'photo/delTimeConf'
    handleRequest(data, fn, url)
  },

  /**
   * 获取拍照医院统计信息
   * @param {*} data 
   * @param {*} fn 
   */
  getPhotoHosStatis:(data, fn)=>{
    let url = 'photo/hosList'
    handleRequest(data, fn, url)
  },

  /**
   * 获取巡检工作人员列表
   * @param {*} data 
   * @param {*} fn 
   */
  getRoutingWorkerList:(data, fn)=>{
    let url = 'user/routingWorker'
    handleRequest(data, fn, url)
  },

  /**
   * 拍照任务审查结果上报
   * @param {*} data 
   * @param {*} fun 
   */
  photoCheckRst:(data, fun)=>{
     let url = 'photo/check';
     handleRequest(data, fun, url)
  },
  
  /**
   * 获取拍照的设备列表
   * @param {*} data 
   * @param {*} fun 
   */
  getPhotoEquList:(data, fun) =>{
    let url = 'photo/equList'
    handleRequest(data, fun, url)
  },

  /**
   * 获取设备的拍照文件信息
   * @param {*} data 
   * @param {*} fun 
   */
  getEquPhotoFiles:(data, fun) =>{
    let url = 'photo/equPhotoList'
    handleRequest(data, fun, url)
  },

  /**
   * 获取设备照片上传的文件列表
   * @param {*} data 
   * @param {*} fun 
   */
  getEquPhotoUploadFiles:(data, fun) =>{
    let url = 'photo/equUploadPhotoList'
    handleRequest(data, fun, url)
  },

  /**
   * 上传照片信息
   * @param {*} data 
   * @param {*} fun 
   */
  uploadPhotoFile:(data, fun) => {
    console.log("upload--->", data)
    let url = util.CONST_DATA.BASE_URL + 'photo/uploadPhoto'
    wx.uploadFile({
      header,
      filePath: data.url,
      name: 'file',
      url: url,
      formData:{
        fileType: data.type,
        fileSize: data.size,
        fileName: data.name,
        equRecordId: data.equRecordId
      },
      success(res) {
         console.log("photoUploadImg --->", res)
         fun(JSON.parse(res.data))
      }

    })
  },

  /**
   * 提交上传的文件
   * @param {*} data 
   * @param {*} fun 
   */
  commitUploadFile:(data, fun) =>{
     let url = 'photo/commitPhotoFile';
     handleRequest(data, fun, url)
  },
    /**
   * 获取数据字典列表
   * @param {*} data 
   * @param {*} fun 
   */
  getDictByCode:(data, fun) =>{
    let url = 'api/task/getDictByCode';
    handleRequest(data, fun, url)
 },
   /**
   * 获取市场所有分类
   * @param {*} data 
   * @param {*} fun 
   */
  getMarketTaskCategoryList:(data, fun) =>{
    let url = 'api/task/getMarketTaskCategoryList';
    handleRequest(data, fun, url)
 },
  /**
   * 获取市场所有机构
   * @param {*} data 
   * @param {*} fun 
   */
  getAllMechanismList:(data, fun) =>{
    let url = 'api/task/getAllMechanismList';
    handleRequest(data, fun, url)
 },
   /**
   * 获取所有用户列表
   * @param {*} data 
   * @param {*} fun 
   */
  getAllUserList:(data, fun) =>{
    let url =  'api/task/getAllUserList';
    handleRequest(data, fun, url)
 },
    /**
   * 添加市场临时任务
   * @param {*} data 
   * @param {*} fun 
   */
  addMarketTaskDevOps:(data, fun) =>{
    let url =  'api/task/addMarketTaskDevOps';
    handleRequest(data, fun, url)
 },
   /**
   * 市场自建临时任务编辑回显
   * @param {*} data 
   * @param {*} fun 
   */
  getMarketTaskDevOpsById:(data, fun) =>{
    let url =  'api/task/getMarketTaskDevOpsById';
    handleRequest(data, fun, url)
 },
    /**
   * 临时任务编辑
   * @param {*} data 
   * @param {*} fun 
   */
  editMarketTaskDevOps:(data, fun) =>{
    let url =  'api/task/editMarketTaskDevOps';
    handleRequest(data, fun, url)
 },
     /**
   * 临时任务删除
   * @param {*} data 
   * @param {*} fun 
   */
  removeTask:(data, fun) =>{
    let url =  'api/task/removeTask';
    handleRequest(data, fun, url)
 },
  /**
   * 获取临时任务详情
   * @param {*} data 
   * @param {*} fun 
   */
  getDetailById:(data, fun) =>{
    let url =  'api/task/market/getDetailById';
    handleRequest(data, fun, url)
 }, 
   /**
   * 获取长期任务详情
   * @param {*} data 
   * @param {*} fun 
   */
  getLongDetailById:(data, fun) =>{
    let url =  'api/task/market/getLongDetailById';
    handleRequest(data, fun, url)
 }, 
   /**
   * 获取分类字典列表
   * @param {*} data 
   * @param {*} fun 
   */
  getCategoryListByParentCode:(data, fun) =>{
    let url =  'api/task/market/getCategoryListByParentCode';
    handleRequest(data, fun, url)
 },
  /**
   * 医院部门联系人树形
   * @param {*} data 
   * @param {*} fun 
   */
  getMechanismDeptUserList:(data, fun) =>{
    let url =  'api/task/market/getMechanismDeptUserList';
    handleRequest(data, fun, url)
 },
  /**
   * 根据医院获取代理列表
   * @param {*} data 
   * @param {*} fun 
   */
  getAgentList:(data, fun) =>{
    let url =  'api/task/market/getAgentList';
    handleRequest(data, fun, url)
 },
  /**
   * 沟通情况
   * @param {*} data 
   * @param {*} fun 
   */
  communicateFeedback:(data, fun) =>{
    let url =  'api/task/market/communicateFeedback';
    handleRequest(data, fun, url)
 },
   /**
   * 沟通情况回显
   * @param {*} data 
   * @param {*} fun 
   */
  getCommunicateFeedback:(data, fun) =>{
    let url =  'api/task/market/getCommunicateFeedback';
    handleRequest(data, fun, url)
 },
   /**
   * 看场地
   * @param {*} data 
   * @param {*} fun 
   */
  lookArea:(data, fun) =>{
    let url =  'api/task/market/lookArea';
    handleRequest(data, fun, url)
 },
    /**
   * 看场地回显
   * @param {*} data 
   * @param {*} fun 
   */
  getLookArea:(data, fun) =>{
    let url =  'api/task/market/getLookArea';
    handleRequest(data, fun, url)
 },
    /**
   * 设备使用汇报
   * @param {*} data 
   * @param {*} fun 
   */
  deviceUseSituation:(data, fun) =>{
    let url =  'api/task/market/deviceUseSituation';
    handleRequest(data, fun, url)
 },
   /**
   * 设备使用汇报回显
   * @param {*} data 
   * @param {*} fun 
   */
  getDeviceUseSituation:(data, fun) =>{
    let url =  '/api/task/market/getDeviceUseSituation';
    handleRequest(data, fun, url)
 },
    /**
   * 采集友商说标人信息
   * @param {*} data 
   * @param {*} fun 
   */
  collectFriendly:(data, fun) =>{
    let url =  'api/task/market/collectFriendly';
    handleRequest(data, fun, url)
 },
     /**
   * 采集友商说标人信息回显
   * @param {*} data 
   * @param {*} fun 
   */
  getCollectFriendly:(data, fun) =>{
    let url =  'api/task/market/getCollectFriendly';
    handleRequest(data, fun, url)
 },
    /**
   * 采集医院信息回显
   * @param {*} data 
   * @param {*} fun 
   */
  getCollectHospital:(data, fun) =>{
    let url =  'api/task/market/getCollectHospital';
    handleRequest(data, fun, url)
 },
    /**
   * 采集医院信息回显
   * @param {*} data 
   * @param {*} fun 
   */
  collectHospital:(data, fun) =>{
    let url =  'api/task/market/collectHospital';
    handleRequest(data, fun, url)
 },
     /**
   * 院内招标说标
   * @param {*} data 
   * @param {*} fun 
   */
  inInviteBid:(data, fun) =>{
    let url =  'api/task/market/inInviteBid';
    handleRequest(data, fun, url)
 },
     /**
   * 院内招标说标回显
   * @param {*} data 
   * @param {*} fun 
   */
  getInInviteBid:(data, fun) =>{
    let url =  'api/task/market/getInInviteBid';
    handleRequest(data, fun, url)
 },
      /**
   * 分类字典获取
   * @param {*} data 
   * @param {*} fun 
   */
  getCategoryListByParentCode:(data, fun) =>{
    let url =  'api/task/market/getCategoryListByParentCode';
    handleRequest(data, fun, url)
 },
   /**
   * 友商说标人沟通情况
   * @param {*} data 
   * @param {*} fun 
   */
  friendlyCommunicate:(data, fun) =>{
    let url =  'api/task/market/friendlyCommunicate';
    handleRequest(data, fun, url)
 },
    /**
   * 友商说标人沟通情况(回显)
   * @param {*} data 
   * @param {*} fun 
   */
  getFriendlyCommunicate:(data, fun) =>{
    let url =  'api/task/market/getFriendlyCommunicate';
    handleRequest(data, fun, url)
 },
     /**
   * 获取代理商列表
   * @param {*} data 
   * @param {*} fun 
   */
  getAllAgent:(data, fun) =>{
    let url =  'api/task/market/getAllAgent';
    handleRequest(data, fun, url)
 },
    /**
   * 新增代理商
   * @param {*} data 
   * @param {*} fun 
   */
  addAgent:(data, fun) =>{
    let url =  'api/task/market/addAgent';
    handleRequest(data, fun, url)
 },
   /**
   * 添加医院
   * @param {*} data 
   * @param {*} fun 
   */
  addMechanism:(data, fun) =>{
    let url =  'api/task/market/addMechanism';
    handleRequest(data, fun, url)
 },
    /**
   * 分类字典子级列表
   * @param {*} data 
   * @param {*} fun 
   */
  getAllCategoryAndSubList:(data, fun) =>{
    let url =  'api/task/market/getAllCategoryAndSubList';
    handleRequest(data, fun, url)
 },
    /**
   * 医院详情查询周边医院列表
   * @param {*} data 
   * @param {*} fun 
   */
  getRoundIncompleteHosInfo:(data, fun) =>{
    let url =  'api/task/getRoundIncompleteHosInfo';
    handleRequest(data, fun, url)
 },
  /**
   * 所有的城市列表
   * @param {*} data 
   * @param {*} fun 
   */
  getCityList:(data, fun) =>{
    let url =  'district/getCityList';
    handleRequest(data, fun, url)
 },
 /**
   * 未巡检列表/设备/控制盒
   * @param {*} data 
   * @param {*} fun 
   */
  getUnInspectEquPileList:(data, fun) =>{
    let url =  'district/getUnInspectEquPileList';
    handleRequest(data, fun, url)
 },
  /**
   * 问题处理
   * @param {*} data 
   * @param {*} fun 
   */
  handleEquInspect:(data, fun) =>{
    let url =  'district/handleEquInspect';
    handleRequest(data, fun, url)
 },
 /**
   * 新获取省市区方法
   * @param {*} data 
   * @param {*} fun 
   */
  getAreaList:(data, fun) =>{
    let url = 'api/task/marketDesk/getAreaList';
    handleRequest(data, fun, url)
 },
  /**
   * 根据条件查询医院
   * @param {*} data 
   * @param {*} fun 
   */
  getHospitalList:(data, fun) =>{
    let url = 'api/task/marketDesk/getHospitalList';
    handleRequest(data, fun, url)
 },
 /**
   * 查询医院详情
   * @param {*} data 
   * @param {*} fun 
   */
  getHospitalInfo:(data, fun) =>{
    let url = 'api/task/marketDesk/getHospitalInfo';
    handleRequest(data, fun, url)
 },
  /**
   * 预估收益
   * 
   * @param {*} fun 
   */
  
    getEstimatedRevenue:(data,fn) =>{
    wx.showLoading({
        title: '加载中...',
        mask: true
      })
      let url = "api/task/marketDesk/getEstimatedRevenue";
      wx.request({
        url: util.CONST_DATA.BASE_URL +url,
        header: {
          'content-type': 'application/json',
          'token': wx.getStorageSync('token') || '',
          'mini_ver':'1.2.1'
        },
        method: method,
        data: data,
        success: function (response) {
          wx.hideLoading()
          handleRes(response, fn, url, data)
        },
        fail: function (error) {
          wx.hideLoading()
          handleErr(error, url, data)
        }
      })
    
  },
  /**
   * 闲置统计查询
   * @param {*} data 
   * @param {*} fun 
   */
  getUnUsedList:(data, fun) =>{
    let url = 'api/task/marketDesk/getUnUsedList';
    handleRequest(data, fun, url)
 },
 /**
   * 调度情况列表
   * @param {*} data 
   * @param {*} fun 
   */
  getDispatchList:(data, fun) =>{
    let url = 'api/task/marketDesk/getDispatchList';
    handleRequest(data, fun, url)
 },
 /**
   * 位置标记
   * @param {*} data 
   * @param {*} fun 
   */
  markPosition:(data, fun) =>{
    let url = 'api/task/marketDesk/markPosition';
    handleRequest(data, fun, url)
 },
 /**
   * 当前机构下桩位闲置情况
   * @param {*} data 
   * @param {*} fun 
   */
  getUnusedPositionDetail:(data, fun) =>{
    let url = 'api/task/marketDesk/getUnusedPositionDetail';
    handleRequest(data, fun, url)
 },
 /**
   * 当前桩位下设备闲置情况
   * @param {*} data 
   * @param {*} fun 
   */
  getUnusedHomingDetail:(data, fun) =>{
    let url = 'api/task/marketDesk/getUnusedHomingDetail';
    handleRequest(data, fun, url)
 },
 /**
   * 位置调度
   * 
   * @param {*} fun 
   */
  
  dispatchPosition:(data,fn) =>{
    wx.showLoading({
        title: '加载中...',
        mask: true
      })
      let url = "api/task/marketDesk/dispatchPosition";
      wx.request({
        url: util.CONST_DATA.BASE_URL +url,
        header: {
          'content-type': 'application/json',
          'token': wx.getStorageSync('token') || '',
          'mini_ver':'1.2.1'
        },
        method: method,
        data: data,
        success: function (response) {
          wx.hideLoading()
          handleRes(response, fn, url, data)
        },
        fail: function (error) {
          wx.hideLoading()
          handleErr(error, url, data)
        }
      })
    
  },
  /**
   * 工作台-用户列表
   * @param {*} data 
   * @param {*} fun 
   */
  getDeskUserList:(data, fun) =>{
    let url = 'api/task/marketDesk/deskUserList';
    handleRequest(data, fun, url)
 },
   /**
   * 费用报销-获取备用金金额
   * @param {*} data 
   * @param {*} fun 
   */
  getImprestInfo:(data, fun) =>{
    let url = 'api/task/marketDesk/getImprestInfo';
    handleRequest(data, fun, url)
 },
  /**
   * 小程序-控制台-巡检截图列表
   * @param {*} data 
   * @param {*} fun 
   */
  getInspectUnshotList:(data, fun) =>{
    let url = 'api/task/marketDesk/getInspectUnshotList';
    handleRequest(data, fun, url)
 },
 /**
   * 待处理需求-列表
   * @param {*} data 
   * @param {*} fun 
   */
  getPendingDemandList:(data, fun) =>{
    let url = 'api/task/marketDesk/getPendingDemand';
    handleRequest(data, fun, url)
 },
 /**
   * 待处理需求-待处理数量
   * @param {*} data 
   * @param {*} fun 
   */
  getPendingDemandNum:(data, fun) =>{
    let url = 'api/task/marketDesk/getPendingDemandNum';
    handleRequest(data, fun, url)
 },
 /**
   * 待处理需求-标记为进行中
   * @param {*} data 
   * @param {*} fun 
   */
  markInProgress:(data, fun) =>{
    let url = 'api/task/marketDesk/markInProgress';
    handleRequest(data, fun, url)
 },
 /**
   * 费用报销统计-月报销统计
   * @param {*} data 
   * @param {*} fun 
   */
  getFeeStatistics:(data, fun) =>{
    let url = 'api/task/marketDesk/getFeeStatistics';
    handleRequest(data, fun, url)
 },
 /**
   * 费用报销-日发票明细
   * @param {*} data 
   * @param {*} fun 
   */
  getDetailFeeList:(data, fun) =>{
    let url = 'api/task/marketDesk/getDetailFeeList';
    handleRequest(data, fun, url)
 },
 /**
   * 费用申诉-申诉列表
   * @param {*} data 
   * @param {*} fun 
   */
  getFeeAppealList:(data, fun) =>{
    let url = 'api/task/marketDesk/feeAppealList';
    handleRequest(data, fun, url)
 },
 /**
   * 费用申诉-取消申诉
   * @param {*} data 
   * @param {*} fun 
   */
  cancelFeeAppeal:(data, fun) =>{
    let url = 'api/task/marketDesk/cancelFeeAppeal';
    handleRequest(data, fun, url)
 },
  /**
   * 费用申诉-提交申诉
   * @param {*} data 
   * @param {*} fun 
   */
  submitFeeAppeal:(data, fun) =>{
    let url = 'api/task/marketDesk/submitFeeAppeal';
    handleRequest(data, fun, url)
 },
   /**
   * 跟进记录-列表
   * @param {*} data 
   * @param {*} fun 
   */
  mechanismFollowRecord:(data, fun) =>{
    let url = 'api/task/marketDesk/mechanismFollowRecord';
    handleRequest(data, fun, url)
 },
    /**
   * 跟进记录-任务列表
   * @param {*} data 
   * @param {*} fun 
   */
  mechanismFollowTaskList:(data, fun) =>{
    let url = 'api/task/marketDesk/mechanismFollowTaskList';
    handleRequest(data, fun, url)
 },
 /**
   * 跟进记录-城市列表
   * @param {*} data 
   * @param {*} fun 
   */
  getFollowCityList:(data, fun) =>{
    let url =  'api/task/getAllCityList';
    handleRequest(data, fun, url)
 },
 /**
   * 签到统计-列表
   * @param {*} data 
   * @param {*} fun 
   */
  getSignStatistics:(data, fun) =>{
    let url =  'api/task/marketDesk/signStatistics';
    handleRequest(data, fun, url)
 },
 /**
   * 签到统计-补签列表
   * @param {*} data 
   * @param {*} fun 
   */
  getApplySignList:(data, fun) =>{
    let url =  'api/task/marketDesk/applySignInList';
    handleRequest(data, fun, url)
 },
 /**
   * 签到统计-补签申请
   * @param {*} data 
   * @param {*} fun 
   */
  marketApplySignIn:(data, fun) =>{
    let url =  'api/task/marketDesk/applySignIn';
    handleRequest(data, fun, url)
 },
 /**
   * 问题列表-获取1分钟/2分钟/五分钟设备巡检列表
   * @param {*} data 
   * @param {*} fun 
   */
  getStatisticsTimeEquList:(data, fun) =>{
    let url =  'api/task/getStatisticsTimeEquList';
    handleRequest(data, fun, url)
 },
}
 

module.exports = lbbTaskService